{extend name="common/application" /}
{block name="title"}<title id="title">店铺中心-订单管理</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/store_center.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
.nodatas{text-align:center;padding:100px 0;width:850px;}
.nodatas img{margin:100px 0 50px 0;}
</style>
{/block}
{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix">
        <!--左菜单-->
        {include file="/common/left" /}

        <!--右内容-->
        <div class="menuContent fr">
            <div class="menuConHeader">
                <!--面包屑导航-->
                <div class="breadcrumb">
                    <p>
                        <a href="javascript:;">订单管理</a> &gt;
                        <a class="curPage" href="{:url('index/store/orders')}">订单管理</a>
                    </p>
                </div>
            </div>
            <div class="menuConBody">
                <div class="courseMenu">
                    <div class="courseSelect">
                        <ul>
                            <li class="selected">
                                <a class="selectType" href="javascript:;">交易类商品</a>
                            </li>
                            <li>
                                <a class="selectType" href="{:url('index/store/store_orders_service')}">服务类商品</a>
                            </li>
                        </ul>
                    </div>
                    <input type="hidden" id="index">
                    <input type="hidden" id="all">
                    <div class="conBody">
                        <div class="orders-main">
                            <!-- 订单状态分类 -->
                            <div class="orders-status">
                                <ul>
                                    <li class="action" all="0">全部订单<span class="order"></span></li>
                                    <li all="1">待选择<span class="order"></span></li>
                                    <li all="2">待支付<span class="order"></span></li>
                                    <li all="3">待上传<span class="order"></span></li>
                                    <li all="4">待确认<span class="order"></span></li>
                                    <li all="10">已取消<span class="order"></span></li>
                                    <li all="9">已完成<span class="order"></span></li>
                                </ul>
                            </div>
                            <!--查询不出数据-->

                            <div class="orders-table-th">
                                <div class="orders-wp">
                                    <div class="orders-th th-item">
                                        <div class="td-inner">商品信息</div>
                                    </div>
                                    <div class="orders-th th-type">
                                        <div class="td-inner">&nbsp;</div>
                                    </div>
                                    <div class="orders-th th-price">
                                        <div class="td-inner">商品金额</div>
                                    </div>
                                    <div class="orders-th th-status">
                                        <div class="td-inner">订单状态</div>
                                    </div>
                                    <div class="orders-th th-op">
                                        <div class="td-inner">操作</div>
                                    </div>
                                </div>
                            </div>
                            <div class="orders-box">
                                <div style="height:auto;" class="caking">
                                </div>
                            </div>
                        </div>


                    </div>
                </div>
            </div>
            <div id="page"></div>
        </div>
    </div>
</div>
{/block}

{block name="js"}

<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/time.js"></script>

<script>

    $(function () {
        postfile(1, 1);
    });
    $(document).ready(function () {
        $('.li3').addClass('showChild');
        $('.li30').addClass('activeMenu');
    });

    $(".selectType").eq(0).on('click', function () {
        $("#index").val(1);
        $(".selectType").eq(1).parent('li').removeClass('selected');
        $(this).parent('li').addClass('selected');
        postfile(1, 1);
    });

    $(".selectType").eq(1).on('click', function () {
        $("#index").val(2);
        $(".selectType").eq(0).parent('li').removeClass('selected');
        $(this).parent('li').addClass('selected');
        postfile(1, 2);
    });

    $(".orders-status li").on('click', function () {
        var index = $("#index").val();
        if (index == '') {
            index = 1;
        }
        $(".action").removeClass('action');
        $(this).addClass('action');
        $("#all").val($(this).attr('all'));
        postfile(1, index, $(this).attr('all'));
    });

    function postfile(page, index, all) {
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            var user_login = $.base64.decode(userinfo).split(",");
            $.ajax({
                type: 'GET',
                url: "{:url('api/shop/orders')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'uid': user_login[0], 'page': page, 'index': index, 'status': all},
                success: function (msg) {
                    if (index == 1) {
                        if (msg.code == 200) {
                            $(".order").eq(0).html(msg.data.all_count);
                            $(".order").eq(1).html(msg.data.count1);
                            $(".order").eq(2).html(msg.data.count2);
                            $(".order").eq(3).html(msg.data.count3);
                            $(".order").eq(4).html(msg.data.count4);
                            $(".order").eq(5).html(msg.data.count5);
                            $(".order").eq(6).html(msg.data.count6);
                            $(".caking").html("");
                            if (msg.data.order.length != 0) {
                                for (var i = 0; i < msg.data.order.length; i++) {
									var store = number_format(msg.data.order[i].store, 2, ".", ",");
									var money = number_format(msg.data.order[i].money, 2, ".", ",");

                                    var html = '<div class="clearfix order-body" id="' + msg.data.order[i].image + '" all="' + msg.data.order[i].order + '"><div class="orders clearfix">' +
                                        '<div class="orders-info"><p><span>' + getMyDate(msg.data.order[i].time * 1000) + '</span>' +
                                        '<span>订单编号：' + msg.data.order[i].order + '</span>';
                                    html += '<span>买家ID：' + msg.data.order[i].u_id + '</span>';
                                    html += '</p></div></div><div class="orders-content"><div class="item-list"><div class="bundle  bundle-last ">' +
                                        '<div class="item-holder"><div class="J_ItemBody item-body clearfix item-normal  first-item">' +
                                        '<ul class="item-content clearfix"><li class="orders-td td-item"><div class="td-inner">' +
                                        '<div class="item-pic J_ItemPic img-loaded"><a href="/index.php/index/trade/trade_details.html?' +
                                        'id=' + msg.data.order[i].name_id + '" target="_blank" class="J_MakePoint" data-point="tbcart.8.12">' +
                                        '<img src="/Images/tradingMarket/' + msg.data.order[i].image + '" class="itempic J_ItemImg"></a>' +
                                        '</div><div class="item-info"><div class="item-basic-info"><a href="/index.php/index/trade/trade_details.html?' +
                                        'id=' + msg.data.order[i].name_id + '" target="_blank" title="" class="item-title J_MakePoint" data-point="tbcart.8.11">' +
                                        '' + msg.data.order[i].username + '</a></div><div class="item-other-info"><div class="item-icon-list clearfix">' +
                                        '<span>交易方式：' + msg.data.order[i].trading_name + '</span></div></div><div class="item-other-info">' +
                                        '<div class="item-icon-list clearfix"><span>行业分类：' + msg.data.order[i].market_name + '</span></div>' +
                                        '</div></div></div></li><li class="orders-td td-type"><div class="item-props item-props-can">' +
                                        '<p class="sku-line" tabindex="0">交易类商品</p></div></li><li class="orders-td td-price">' +
                                        '<div class="td-inner"><div class="item-price price-promo-"><div class="price-content">';
                                        if(msg.data.order[i].money == '0.00'){
											html += '<div class="price-line" style="color:#333">原价：<br><span class="price-now" style="color:red">￥' + store + '</span></div>' +
											'<div class="price-line" style="color:#333;">报价：<br><span class="price-now" style="color:red">待选择</span></div>';
										}else{
											html += '<div class="price-line" style="color:#333">原价：<br><span class="price-now" style="color:red">￥' + store + '</span></div>' +
											'<div class="price-line" style="color:#333;">报价：<br><span class="price-now" style="color:red">￥' + money + '</span></div>';
										}
                                        html += '</div></div></div></li><li class="orders-td td-status"><div class="item-props item-props-can orders-status-inf">';
                                    if (msg.data.order[i].status == 1) {
                                        html += '<p>买家已提交订单，等待选择买家</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情</a>' +
                                            '</p></div></li><li class="orders-td td-op"><div class="td-inner">' +
                                            '<p>剩余' + msg.data.order[i].shi_time + '</p>' +
                                            '<a href="javascript:;" class="J_Del J_MakePoint" onclick="choose_buyers(' + msg.data.order[i].seller + ',' + msg.data.order[i].name_id + ',1)">选择买家</a>' +
                                            '</div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 2) {
                                        html += '<p>已选择买家，等待买家付款</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li><li class="orders-td td-op"><div class="td-inner"><p>剩余' + msg.data.order[i].shi_time + '</p>' +
                                            '</div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 3 && msg.data.order[i].index == 0) {
                                        html += ' <p>买家已付款，等待上传专利文件,<br><span style="color: red;font-size: 12px;">注:只能上传三次</span></p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情</a></p>' +
                                            '</div></li><li class="orders-td td-op"><div class="td-inner">' +
                                            '<a href="javascript:;" class="J_Del J_MakePoint" onclick="upload_file(' + msg.data.order[i].id + ')">上传专利文件</a>' +
                                            '</div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 3 && msg.data.order[i].index != 0) {
                                        html += '<p>专利文件已上传,等待买家确认<br><span style="color: red;font-size: 12px;">注:只能上传三次</span></p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情</a></p>' +
                                            '</div></li><li class="orders-td td-op"><div class="td-inner">' +
                                            '<a href="javascript:;" class="J_Del J_MakePoint" onclick="upload_file(' + msg.data.order[i].id + ')">重新上传专利文件</a></div>' +
                                            '</li></ul></div></div></div></div></div></div>';
                                    }  else if (msg.data.order[i].status == 4) {
                                        html += '<p>专利文件已上传，等待买家确认<br><span style="color: red;font-size: 12px;">注:只能上传三次</span></p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情</a></p>' +
                                            '</div></li><li class="orders-td td-op">' +
                                            '</li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 5) {
                                        html += '<p>买家已确认，上传快递单号</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li><li class="orders-td td-op"><div class="td-inner">' +
                                            '<a href="javascript:;"  class="J_Del J_MakePoint" onclick="upload_tracking(' + msg.data.order[i].id + ')">上传快递单号</a>' +
                                            '</div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 6) {
                                        html += '<p>快递单号已上传，等待买家确认收货</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li><li class="orders-td td-op"><div class="td-inner"></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 7) {
                                        html += '<p>买家已确认收货，订单已完成，等待平台打款</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li><li class="orders-td td-op"></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 8) {
                                        html += '<p>平台已打款，等待商家确认收款</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li><li class="orders-td td-op"><div class="td-inner">' +
                                            ' <a href="javascript:;"  class="J_Del J_MakePoint" onclick="confirmation_receivables(' + msg.data.order[i].id + ')">确认收款</a>' +
                                            '</div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 9) {
                                        html += '<p>商家已确认收款，订单已完成</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 10) {
                                        html += '<p>买家14个自然日内没有付款，订单取消</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 11) {
                                        html += '<p>长时间未操作,订单取消</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].status == 12) {
                                        html += '<p>买家取消订单</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    }else if (msg.data.order[i].status == 13) {
                                        html += '<p>退款成功，订单结束</p><p><a title="查看详情" href="#" onclick="view_detials(' + msg.data.order[i].id + ')">查看详情 </a> ' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    }
                                    $(".caking").append(html);
                                }
                                if (all == 0) {
                                    var king = msg.data.all_count;
                                } else if (all == 1) {
                                    king = msg.data.count1;
                                } else if (all == 2) {
                                    king = msg.data.count2;
                                } else if (all == 3) {
                                    king = msg.data.count3;
                                } else if (all == 4) {
                                    king = msg.data.count4;
                                } else if (all == 10) {
                                    king = msg.data.count5;
                                } else if (all == 9) {
                                    king = msg.data.count6;
                                }
                                if (king == 0) {
                                    $('#page').html('');
                                } else {
                                    $('#page').html(msg.data.render);
                                    $("#pagination").delegate("a", "click", function () {
                                        var index = $("#index").val();
                                        var all = $("#all").val();
                                        if (index == '') {
                                            index = 1;
                                        }
                                        var num = $(this).attr("num");
                                        if (num) {
                                            postfile(num, index, all);
                                        }
                                    });
									var pages = Math.ceil(msg.data.count / 10);
									$("#GO").on('click',function(){
										var king = $("#go").val();
										if(king > pages){
											layer.alert("最多输入"+pages+"页");
											return;
										}
										postfile(king, index,all);
									});
                                }

                                /*申诉*/
                                $('.appeal').on('click', function () {
                                    var order = $(this).parents('div.order-body').attr('all');
                                    var image = $(this).parents('div.order-body').attr('id');
                                    layer.open({
                                        type: 2,
                                        title: '申诉',
                                        fix: false,
                                        maxmin: true,
                                        shadeClose: true,
                                        scrollbar: false,
                                        area: ['720px', '700px'],
                                        content: 'my_appeal.html#' + order,
                                        btn: ['确认申诉', '取消'],
                                        yes: function (index, layero) {
                                            //do something
                                            var body = layer.getChildFrame('body', index);
                                            //body.find("#user_id").val(user_uid);
                                            var formData = new FormData(body.find('form')[0]);
                                            formData.append('uid', user_login[0]);
                                            formData.append('image', "tradingMarket/" + image);
                                            formData.append('order', order);
                                            formData.append('status', 2);
                                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                                            $.ajax({
                                                type: "post",
                                                url: "/index.php/api/form/appeal",
                                                data: formData,
                                                dataType: 'json',
												beforeSend: function () {
												var index = layer.load(1, {
													shade: [0.1, '#333333'] //0.1透明度的白色背景
												});
												},
                                                success: function (msg) {
                                                    layer.closeAll();
                                                    if (msg.code == 200) {
                                                        postfile(page, 1);
                                                    }
                                                    if (msg.code == 1000) {
                                                        layer.msg('修改失败！', {icon: 5});
                                                    }
                                                },
                                                contentType: false, //必须false才会自动加上正确的Content-Type
                                                processData: false //必须false才会避开jQuery对 formdata 的默认处理
                                            });
                                        }
                                    });
                                });

                            } else {
								$('.orders-table-th').css('display','none');
                                $(".caking").append('<div class="nodatas"><img src="/static/web/images/nodatas01.png"/>' +
                                    '<p>抱歉，暂无订单</p></div>')
                            }
                        } else {
                            layer.msg('查询失败!', {icon: 1, time: 1000});
                        }
                    } else {

                    }
                }
            })
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    }


    //选择买家
    function choose_buyers(uid, id, value) {
        var page_id = "#" + $(".current").attr('num');
        var all = "#" + $("#all").val();
        layer.open({
            type: 2,
            title: '选择买家',
            skin: 'layui-layer-lan',
            area: ['1023px', '685px'], //宽高
            content: 'orders_choose.html#' + uid + "#" + id + "#" + value + page_id + all
        });
    }

    //订单详细情况
    function view_detials(id) {
        var index = $("#index").val();
        var all = $("#all").val();
        window.location.href = 'order_details.html?id=' + id + '=' + 1
    }


    //上传专利文件
    function upload_file(id) {
        var index = $("#index").val();
        var all = $("#all").val();
        layer.open({
            type: 2,
            title: '上传专利文件',
            skin: 'layui-layer-lan',
            area: ['650px', '400px'], //宽高
            content: 'upload_file.html#' + id + "#" + index + "#" + all
        });
    }

    //上传快递单号
    function upload_tracking(id) {
        var index = $("#index").val();
        var all = $("#all").val();
        layer.open({
            type: 2,
            title: '上传快递单号',
            skin: 'layui-layer-lan',
            area: ['570px', '200px'], //宽高
            content: 'upload_caking.html#' + id + "#" + index + "#" + all
        });
    }

    //确认收款
    function confirmation_receivables(id) {
        var index = $("#index").val();
        var all = $("#all").val();
        layer.open({
            type: 2,
            title: '确认收款',
            skin: 'layui-layer-lan',
            area: ['570px', '360px'], //宽高
            content: 'confirmation_receivables_trading.html#' + id + "#" + index + "#" + all
        });
    }
</script>
{/block}
